#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include <string.h>
#include <sys/socket.h>   // For Socket Functions
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>

#include "util.h"


void
handle_prov_request (int fd)
{
    /*
     * 1. Accept the conection
     * 2. Start thread to handle the request.
     */
    int cSocket = -1;
    socklen_t len = 0;
    struct sockaddr_in cAddress;
    char client_ip[INET_ADDRSTRLEN + 1];

    LOG(DEBUG, "Inside handle_connect_request");

    memset((void *)&cAddress, 0, sizeof(struct sockaddr_in));

    cSocket = accept(fd, (struct sockaddr*) &cAddress, &len);
    if (cSocket == -1){
        LOG(ERROR, "Failed in accept with error: %d", errno);
        return;
    }
    
    LOG(DEBUG, "Connection from %s, port %d\n",
        inet_ntop(AF_INET, &cAddress.sin_addr, client_ip,
                  sizeof(client_ip)), ntohs(cAddress.sin_port));
    LOG(DEBUG, "Assigned socket %d for the client", cSocket);
    // condtion broadcast
    
}

